// 注释规则
// https://www.npmjs.com/package/eslint-plugin-jsdoc/v/30.3.1
// 【中文版】 https://www.5axxw.com/wiki/content/vsz98f
// https://eslint.org/docs/developer-guide/selectors
// https://astexplorer.net/
// eslint的jsdoc已废弃： https://eslint.org/docs/rules/valid-jsdoc
/**
 * 参考:https://tsdoc.org/
 * 建议安装vscode扩展:Document This
 */
module.exports = {
    extends: ["plugin:jsdoc/recommended"],
    plugins: ["jsdoc"],
    rules: {
        // 对齐
        "jsdoc/check-alignment": "warn",
        // 无效填充,就不检测了吧！
        "jsdoc/check-indentation": ["off", { excludeTags: ["example", "roadmap", "description"] }],
        // @param后的参数名和函数声明中的参数名匹配
        "jsdoc/check-param-names": "warn",
        // 检测tag的名字
        "jsdoc/check-tag-names": "warn",
        // 允许出现没有定义的type
        "jsdoc/no-undefined-types": "off",
        // 检测public、private、protected、package
        "check-access": "off",
        // 检测文件描述中version since license author 是否有值
        "check-values": "off",
        // 需要注释
        "jsdoc/require-jsdoc": ["warn", {
            require: {
                // 箭头函数不需要注释
                "ArrowFunctionExpression": false,
                "ClassDeclaration": true,
                "ClassExpression": true,
                "FunctionDeclaration": true,
                "FunctionExpression": true,
                "MethodDefinition": false,
            },
            // constructor不需要注释
            checkConstructors: false,
            contexts:[
                // 类身上的属性
                "ClassProperty",
                // interface、type定义的属性需要注释
                { context: "TSPropertySignature", inlineCommentBlock:true },
                // 检测ts中的type。除去Props和State结尾的
                { context: "TSTypeAliasDeclaration:not([id.name=/.*(Props|State)$/])", inlineCommentBlock:true },
                // 检测ts中的interface。除去Props和State结尾的
                { context: "TSInterfaceDeclaration:not([id.name=/.*(Props|State)$/])", inlineCommentBlock:true },
                // 类中定义的挂载原型对象上的方法属性要注释
                { context: "PropertyDefinition:not([key.name=/^(state|handle|render|component|get).*/])", inlineCommentBlock:true },
                // 类中的方法
                { context: "TSMethodSignature:not([key.name=/^(state|handle|render|component|get).*/])", inlineCommentBlock:true },
                { context: "MethodDefinition:not([key.name=/^(state|handle|render|component|get).*/])", inlineCommentBlock:true },
            ],

        }],
    },
    settings: {
        jsdoc: {
            // 设置tagName别名(不准确的描述)
            "check-tag-names": "off",
            tagNamePreference: {
                returns: {
                    message: "@return 来描述当前函数返回的值类型",
                    replacement: "return"
                },
                date: {
                    message: "@date 来描述当前代码块创建日期",
                    replacement: "date"
                },
                extends: {
                    message: "@extends 来描述当前类继承自哪个类",
                    replacement: "extends"
                },
                author: {
                    message: "@author 来描述创建这个代码块的作者",
                    replacement: "author"
                },
                param: {
                    message: "@param 来描述当前参数的类型和作用",
                    replacement: "param"
                },
                roadmap: {
                    message: "@roadmap 来描述当前代码块的需改记录",
                    replacement: "roadmap"
                }
            },
        }
    }
}